package com.ruoyi.flowable.FlowListeners;

import cn.hutool.core.convert.Convert;
import com.ruoyi.flowable.common.constant.ProcessConstants;
import com.ruoyi.flowable.common.enums.ProcessStatus;
import com.ruoyi.flowable.service.ProcessListenerInter;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent;
import org.flowable.engine.RuntimeService;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * @author linziheng
 */
@Component
public class DemoListener implements ProcessListenerInter {

    private ApplicationContext applicationContext ;
    @Override
    public void processCompleted(FlowableEngineEntityEvent event) {
        String processInstanceId = event.getProcessInstanceId();


        RuntimeService runtimeService = applicationContext.getBean(RuntimeService.class);
        Object variable = runtimeService.getVariable(processInstanceId, ProcessConstants.PROCESS_STATUS_KEY);
        // 流程状态
        ProcessStatus status = ProcessStatus.getProcessStatus(Convert.toStr(variable));

    }

    @Override
    public void setApplilcation(ApplicationContext app) {
        this.applicationContext = app;
    }
}
